<?php
namespace Common\Model;
use Think\Model;

class BaseModel extends Model{
    //操作按钮的基本样式
    protected $action_button_class = "btn btn-sm btn-rounded";

    /**
     * 获取单个字段数据
     * @param $where
     * @param $field
     * @param $order
     * @return mixed
     */
    public function getFieldData($where = array(),$field = "",$order = ""){
        $result = $this
            ->where($where)
            ->order($order)
            ->getField($field);
        return $result;
    }

    /**
     * 获取单条数据
     * @param array $where
     * @param array $field
     * @param string $order
     * @return mixed
     */
    public function getFindData($where = array(),$field = array(),$order = ""){
        $result = $this
            ->where($where)
            ->order($order)
            ->field($field)
            ->find();
        return $result;
    }

    /**
     * @param $where:查询过滤条件
     * @param $field:显示列
     * @param $order:排序规则
     * @param $limit:分页
     * @return mixed:列表数据
     */
    public function getListData($where = array(),$field = array(),$order = "",$limit = ""){
        $result = $this
            ->where($where)
            ->field($field)
            ->order($order)
            ->limit($limit)
            ->select();
        return $result;
    }

    /**
     * @param $where:查询过滤规则
     * @return mixed:列数据总量
     */
    public function getListCount($where = array()){
        $count = $this
            ->where($where)
            ->count();
        return $count;
    }
}
?>